package main

import (
	"fmt"
	"log"
	"net/http"
)

// step 1 原生net/http的web功能实现
func main() {
	http.HandleFunc("/", indexHandle)
	http.HandleFunc("/hello", helloHandle)
	// The handler is typically nil, in which case the DefaultServeMux is used.
	// 传入nil，默认使用 DefaultServeMux
	log.Fatal(http.ListenAndServe(":8000", nil))
}

// handle echoes r.URL.Path
func indexHandle(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "URL.PAth = %q\n", r.URL.Path)
}

// handle echoes r.URL.Header
func helloHandle(w http.ResponseWriter, r *http.Request) {
	for k, v := range r.Header {
		fmt.Fprintf(w, "Header[%q] = %q\n", k, v)
	}
}